package com.xiaomaoguai.consul;

import com.orbitz.consul.AgentClient;
import com.orbitz.consul.Consul;
import com.orbitz.consul.model.health.Service;

import java.util.Map;

/**
 * @fileName: ConsulTest.java
 * @author: WeiHui
 * @date: 2018/5/22 10:14
 * @version: v1.0.0
 * @since JDK 1.7
 */
public class ConsulTest {


    public static void main(String[] args) {
        Consul consul = Consul.builder().withUrl("http://consul.zhonganonline.com").build();

        AgentClient agentClient = consul.agentClient();

        Map<String, Service> services = agentClient.getServices();

        services.forEach((k, v) -> {
            if (k.contains("cs")) {
                test(k, v.getAddress(), v.getPort());
            }
        });

    }

    public static void test(String serviceName, String ip, int port) {
        String url = "http://" + ip + ":" + port;
        System.out.println("serviceName: " + serviceName + ", url: " + url);
    }

}